/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package se.kth.lwr.jeat.samples.onsitetreatment;

import se.kth.lwr.jeat.samples.onsitetreatment.producers.PolyEtenPipeProducer;
import se.kth.lwr.jeat.samples.onsitetreatment.producers.StainlessSteelProducer;
import javax.measure.quantity.Duration;
import javax.measure.quantity.Length;
import javax.measure.quantity.Mass;
import javax.measure.quantity.Volume;
import javax.measure.unit.NonSI;
import javax.measure.unit.SI;
import javax.measure.unit.Unit;
import org.jscience.physics.amount.Amount;
import se.kth.lwr.jeat.core.Activity;
import se.kth.lwr.jeat.core.ActivityCategory;
import se.kth.lwr.jeat.core.Inventory;
import se.kth.lwr.jeat.core.AmountDataSource;
import se.kth.lwr.jeat.core.EnergyCategory;

/**
 *
 * @author davidev
 */
public class LocalWaterWell extends Activity {

    public LocalWaterWell(String name, String description) {
        super(name, description);
        addSubActivities();
    }

    @Override
    public Inventory contribute(Inventory inventory) {
        return inventory;
    }

    private void addSubActivities() {
        //add production of casing tube
        addChild(StainlessSteelProducer.getInstance().getProduction(
                "Casing tube production",
                "Production of casing tube for water well",
                Amount.valueOf(0.024, SI.CUBIC_METRE),
                Amount.valueOf("15 year"),
                Scenario1.systemUsers));
        addChild(StainlessSteelProducer.getInstance().getProduction(
                "Steel for pump",
                "Steelproduction for water well pump",
                Amount.valueOf("12 kg"),
                Amount.valueOf("10 year"),
                Scenario1.systemUsers));
        addChild(StainlessSteelProducer.getInstance().getProduction(
                "hydrofor production",
                "production of hydrofor for water distribution",
                Amount.valueOf("35 kg"),
                Amount.valueOf("30 year"),
                Scenario1.systemUsers));
        addChild(PolyEtenPipeProducer.getInstance().getProduction(
                "PEM pipe",
                "Production of 32mm PEM pipe for water distribution",
                (Amount<Length>) Amount.valueOf("80 m"),
                Amount.valueOf("50 year"),
                Scenario1.systemUsers));
        Activity operation = new DrinkingWaterMainTainess("Well operation", "Operation of water well");
        operation.joinCategory(ActivityCategory.MAINTAINANCE_PHASE);
        addChild(operation);
    }
    
    //an activity that describes energy consumption during maintaines

    class DrinkingWaterMainTainess extends Activity {

        public DrinkingWaterMainTainess(String name, String description) {
            super(name, description);
        }

        @Override
        public Inventory contribute(Inventory inventory) {
            inventory.addEnergyUse(EnergyCategory.ELECTRICAL, pumpEneryUse.useValue(this));
            return inventory;
        }
        /**
         * Enery consumtion during operation of pump
         * <p/>
         * Value: 10
         * <p/>
         * Unit: MJ/year
         */
        final AmountDataSource pumpEneryUse = new AmountDataSource<>(
                "pumpEneryUse",
                "Enery consumtion during operation of pump",
                Amount.valueOf(10, Unit.valueOf("MJ/year")).divide(Scenario1.systemUsers.useValue(this)));
    }
}
